"""
管理员管理序列化器
"""
from rest_framework import serializers
from users.models import User
from django.contrib.auth.models import Group
from django.contrib.auth.hashers import make_password

class GroupSimpleSerializer(serializers.ModelSerializer):
    class Meta:
        model = Group
        fields = ['id', 'name']


class AdminSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ['id', 'username', 'email', 'mobile',
        'groups',
        'user_permissions',
        'password'
        ]

        extar_kwargs = {
            'password': {'write_only': True}
        }

    def validate(self, attrs):
        attrs['is_staff'] = True
        rem_password = attrs['password']
        attrs['password'] = make_password(rem_password)
        return attrs